home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / security / portmap.shar / pmap_dump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-06  |  1.3 KB  |  64 lines

  1.  /*
  2.   * pmap_dump - dump portmapper table in format readable by pmap_set
  3.   * 
  4.   * Author: Wietse Venema (wietse@wzv.win.tue.nl), dept. of Mathematics and
  5.   * Computing Science, Eindhoven University of Technology, The Netherlands.
  6.   */
  7.  
  8. #ifndef lint
  9. static char sccsid[] = "@(#) pmap_dump.c 1.1 92/06/11 22:53:15";
  10. #endif
  11.  
  12. #include <stdio.h>
  13. #include <sys/types.h>
  14. #ifdef SYSV40
  15. #include <netinet/in.h>
  16. #include <rpc/rpcent.h>
  17. #else
  18. #include <netdb.h>
  19. #endif
  20. #include <rpc/rpc.h>
  21. #include <rpc/pmap_clnt.h>
  22. #include <rpc/pmap_prot.h>
  23.  
  24. static char *protoname();
  25.  
  26. main(argc, argv)
  27. int     argc;
  28. char  **argv;
  29. {
  30.     struct sockaddr_in addr;
  31.     register struct pmaplist *list;
  32.     register struct rpcent *rpc;
  33.  
  34.     get_myaddress(&addr);
  35.  
  36.     for (list = pmap_getmaps(&addr); list; list = list->pml_next) {
  37.     rpc = getrpcbynumber((int) list->pml_map.pm_prog);
  38.     printf("%10lu %4lu %5s %6lu  %s\n",
  39.            list->pml_map.pm_prog,
  40.            list->pml_map.pm_vers,
  41.            protoname(list->pml_map.pm_prot),
  42.            list->pml_map.pm_port,
  43.            rpc ? rpc->r_name : "");
  44.     }
  45. #undef perror
  46.     return (fclose(stdout) ? (perror(argv[0]), 1) : 0);
  47. }
  48.  
  49. static char *protoname(proto)
  50. u_long  proto;
  51. {
  52.     static char buf[BUFSIZ];
  53.  
  54.     switch (proto) {
  55.     case IPPROTO_UDP:
  56.     return ("udp");
  57.     case IPPROTO_TCP:
  58.     return ("tcp");
  59.     default:
  60.     sprintf(buf, "%lu", proto);
  61.     return (buf);
  62.     }
  63. }
  64.